home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BCI NET
/
BCI NET Dec 94.iso
/
archives
/
applications
/
wp
/
ghostscript2_6_1.lha
/
amiga-src
/
gp_amiga.c
< prev
Wrap
C/C++ Source or Header
|
1993-05-15
|
8KB
|
334 lines
/* Copyright (C) 1989, 1990, 1991 Aladdin Enterprises. All rights reserved.
Distributed by Free Software Foundation, Inc.
This file is part of Ghostscript.
Ghostscript is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves any
particular purpose or works at all, unless he says so in writing. Refer
to the Ghostscript General Public License for full details.
Everyone is granted permission to copy, modify and redistribute
Ghostscript, but only under the conditions described in the Ghostscript
General Public License. A copy of this license is supposed to have been
given to you along with Ghostscript so you can know your rights and
responsibilities. It should be in a file named COPYING. Among other
things, the copyright notice and this notice must be preserved on all
copies. */
/* gp_amiga.c */
/* Amiga specific routines for Ghostscript */
#define timeval foo
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <dos/dosextens.h>
#include <inline/exec.h>
#include <inline/dos.h>
#define ushort foo
#include <signal.h>
#undef ushort
#undef timeval
/* gp_amiga.c */
/* Amiga-specific routines for Ghostscript */
#include "memory_.h"
#include "string_.h"
#include "gx.h"
#include "gp.h"
#include "stat_.h"
#include "time_.h"
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct Library *LayersBase,
*IFFParseBase,
*UtilityBase;
/* Nothing happens here */
void
gs_amiga_init()
{
}
void
gp_exit(int exit_status, int code)
{
}
/* Cleanup routine, as called by atexit() trap */
void
cleanup()
{
extern void devcleanup();
devcleanup();
if(IFFParseBase)
{
CloseLibrary(IFFParseBase);
IFFParseBase = NULL;
}
if(UtilityBase)
{
CloseLibrary(UtilityBase);
UtilityBase = NULL;
}
if(LayersBase)
{
CloseLibrary(LayersBase);
LayersBase = NULL;
}
if(GfxBase)
{
CloseLibrary((struct Library *)GfxBase);
GfxBase = NULL;
}
if(IntuitionBase)
{
CloseLibrary((struct Library *)IntuitionBase);
IntuitionBase = NULL;
}
}
void
signal_handler(int signal)
{
fprintf(stderr,"*** BREAK: Ghostscript\a\n");
exit(1);
}
/* Do platform-dependent initialization */
void
gp_init()
{
atexit(cleanup);
signal(SIGINT,signal_handler);
if(!(IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",37)))
{
perror("Ghostscript: cannot open intuition.library v37");
exit(20);
}
if(!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",37)))
{
perror("Ghostscript: cannot open graphics.library v37");
exit(20);
}
if(!(LayersBase = OpenLibrary("layers.library",37)))
{
perror("Ghostscript: cannot open layers.library v37");
exit(20);
}
if(!(UtilityBase = OpenLibrary("utility.library",37)))
{
perror("Ghostscript: cannot open utility.library v37");
exit(20);
}
if(!(IFFParseBase = OpenLibrary("iffparse.library",37)))
{
perror("Ghostscript: cannot open iffparse.library v37");
exit(20);
}
}
/* Read the current date (in days since Jan. 1, 1980) */
/* and time (in milliseconds since midnight). */
void
gp_get_clock(long *pdt)
{
struct DateStamp Date;
DateStamp(&Date);
pdt[0] = Date . ds_Days + 2 * 365;
pdt[1] = (Date . ds_Minute * 60 + Date . ds_Tick / TICKS_PER_SECOND) * 1000;
}
/* ------ Printer accessing ------ */
/* Open a connection to a printer. A null file name means use the */
/* standard printer connected to the machine, if any. */
/* "|command" opens an output pipe. */
/* Return NULL if the connection could not be opened. */
FILE *
gp_open_printer(char *fname, int binary_mode)
{ return
(strlen(fname) == 0 ?
gp_open_scratch_file(gp_scratch_file_name_prefix, fname, "w") :
fname[0] == '|' ?
popen(fname + 1, "w") :
fopen(fname, "w"));
}
/* Close the connection to the printer. */
void
gp_close_printer(FILE *pfile, const char *fname)
{ if ( fname[0] == '|' )
pclose(pfile);
else
fclose(pfile);
}
/* ------ File name syntax ------ */
/* Define the character used for separating file names in a list. */
const char gp_file_name_list_separator = ',';
/* Define the default scratch file name template. */
const char gp_scratch_file_name_prefix[] = "T:gs_";
/* Define the string to be concatenated with the file mode */
/* for opening files without end-of-line conversion. */
const char gp_fmode_binary_suffix[] = "b";
/* Define the file modes for binary reading or writing. */
const char gp_fmode_rb[] = "r";
const char gp_fmode_wb[] = "w";
/* Create and open a scratch file with a given name prefix. */
/* Write the actual file name at fname. */
FILE *
gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
{
strcpy(fname,prefix);
/* Prevent trailing X's in path from being converted by mktemp. */
if ( *fname != 0 && fname[strlen(fname) - 1] == 'X' )
strcat(fname, "-");
strcat(fname, "XXXXXX");
mktemp(fname);
return fopen(fname, mode);
}
/* Answer whether a file name contains a directory/device specification, */
/* i.e. is absolute (not directory- or device-relative). */
int
gp_file_name_is_absolute(const char *fname, uint len)
{
int i;
for(i = 0 ; i < len ; i++)
{
if(fname[i] == ':')
return(1);
}
return(0);
}
/* Answer the string to be used for combining a directory/device prefix */
/* with a base file name. The file name is known to not be absolute. */
const char *
gp_file_name_concat_string(const char *prefix, uint plen, const char *fname, uint len)
{
if(plen > 0 && (prefix[plen - 1] == '/' || prefix[plen - 1] == ':'))
return("");
else
return("/");
}
/* ------ File operations ------ */
/* If the file given by fname exists, fill in its status and return 1; */
/* otherwise return 0. */
int
gp_file_status(const char *fname, file_status *pstatus)
{ struct stat sbuf;
/* The RS/6000 prototype for stat doesn't include const, */
/* so we have to explicitly remove the const modifier. */
if ( stat((char *)fname, &sbuf) < 0 ) return 0;
pstatus->size_pages = stat_blocks(&sbuf); /* st_blocks is */
/* missing on some systems, */
/* see stat_.h */
pstatus->size_bytes = sbuf.st_size;
pstatus->time_referenced = sbuf.st_mtime;
pstatus->time_created = sbuf.st_ctime;
return 1;
}
/* ------ File enumeration ------ */
/****** THIS IS NOT SUPPORTED ON UNIX SYSTEMS. ******/
/* Amazingly enough, there is no standard Unix library routine */
/* for enumerating the files matching a pattern, */
/* or even for enumerating (conveniently) the files in a directory. */
struct file_enum_s {
char *pattern;
int first_time;
const gs_memory_procs *mprocs;
};
/* Initialize an enumeration. NEEDS WORK ON HANDLING * ? \. */
file_enum *
gp_enumerate_files_init(const char *pat, uint patlen,
const gs_memory_procs *mprocs)
{ file_enum *pfen = (file_enum *)(*mprocs->alloc)(1, sizeof(file_enum), "gp_enumerate_files");
char *pattern;
if ( pfen == 0 ) return 0;
pattern = (*mprocs->alloc)(patlen + 1, 1,
"gp_enumerate_files(pattern)");
if ( pattern == 0 ) return 0;
memcpy(pattern, pat, patlen);
pattern[patlen] = 0;
pfen->pattern = pattern;
pfen->mprocs = mprocs;
pfen->first_time = 1;
return pfen;
}
/* Enumerate the next file. */
/* PUNT: JUST RETURN THE PATTERN. */
uint
gp_enumerate_files_next(file_enum *pfen, char *ptr, uint maxlen)
{ if ( pfen->first_time )
{ char *pattern = pfen->pattern;
uint len = strlen(pattern);
pfen->first_time = 0;
if ( len > maxlen )
return maxlen + 1;
strcpy(ptr, pattern);
return len;
}
return -1;
}
/* Clean up the file enumeration. */
void
gp_enumerate_files_close(file_enum *pfen)
{ const gs_memory_procs *mprocs = pfen->mprocs;
(*mprocs->free)(pfen->pattern, strlen(pfen->pattern) + 1, 1,
"gp_enumerate_files_close(pattern)");
(*mprocs->free)((char *)pfen, 1, sizeof(file_enum),
"gp_enumerate_files_close");
}